#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/acaccountao_stub4web_allinone.h"
#include <set>	
#include "erp/acaccount/po/acitemsfilterpo_acaccount.h"	
#include <map>	
#include "erp/acaccount/po/bankaccountfilterpo_acaccount.h"	
#include <vector>	
#include "erp/acaccount/po/bankaccountpo_acaccount.h"	
#include "erp/acaccount/po/acitemspo_acaccount.h"	
#include "erp/acaccount/ddo/bankaccountddo_acaccount.h"
#include "erp/acaccount/ddo/bankaccountfilterddo_acaccount.h"

using namespace erp::acaccount::ao;

void Init()
{
	if (CCGI_STUB_CNTL->Initialize(true) != 0)
	std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(5);
}
void TestAddAndUpdateACItems()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";
	std::string source = "";
	uint32_t sceneId = 0;
	erp::acaccount::po::CACItemsPo aCItemsPo;
	std::string inReserve = "";
	std::string errmsg = "";
	uint64_t aCItemsSysNo = 0;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数
	uint32_t dwResult = oStub.AddAndUpdateACItems(oCntlInfo, machineKey, source,
			sceneId, aCItemsPo, inReserve, errmsg, aCItemsSysNo, outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n", dwResult,
				oStub.GetLastConsumeTime());
	}
	else
	{
		printf("Error result[0x%x], time = %ld , errmsg = [%s]\n", dwResult,
				oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
void TestAddAndUpdateBankAccount()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(100);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(100);
	std::string machineKey = "10.12.194.127";
	std::string source = "acaccountdao_test";
	uint32_t sceneId = 10;
	//erp::acaccount::po::CBankAccountPo bankAccount;
	std::string inReserve = "";
	std::string errmsg = "";
	uint64_t bankAccountSysNo = 0;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数
	for (int i = 1; i <= 10; i++)
	{
		erp::acaccount::po::CBankAccountPo bankAccount;

		std::stringstream strFBankAccount;
		strFBankAccount << "银行账户_20131031" << i;
		std::stringstream strFBankAccountName;
		strFBankAccountName << "工商银行_20131031" << i;
		std::stringstream strFBranchBank;
		strFBranchBank << "工商银行漕河泾支行_20131031" << i;
		std::stringstream strFBankType;
		strFBankType << "银行类型_20131031" << i;
		std::stringstream strFComment;
		strFComment << "徐威备注_20131031" << i;

		bankAccount.SetBankAccount(strFBankAccount.str());
		bankAccount.SetBankAccountName(strFBankAccountName.str());
		//bankAccount.SetBankAccountSysNo(i);
		bankAccount.SetBankType(strFBankType.str());
		bankAccount.SetBranchBank(strFBranchBank.str());
		bankAccount.SetComment(strFComment.str());
		bankAccount.SetCreatorSysNo(33);
		bankAccount.SetModifierSysNo(23);
		bankAccount.SetParentBankAccountSysNo(0);
		//bankAccount.SetProperty(0);
		bankAccount.SetStatus(1);
		bankAccount.SetVersion(0);

		// TODO:替换函数参数
		uint32_t dwResult = oStub.AddAndUpdateBankAccount(oCntlInfo, machineKey,
				source, sceneId, bankAccount, inReserve, errmsg,
				bankAccountSysNo, outReserve);
		if (dwResult == 0)
		{
			std::cout << "Invoke OK!" << std::endl;
			printf("TestAddAndUpdateBankAccount OK result[0x%x], time = %ld\n",
					dwResult, oStub.GetLastConsumeTime());
		}
		else
		{
			printf(
					"TestAddAndUpdateBankAccount Error result[0x%x], time = %ld , errmsg = [%s]\n",
					dwResult, oStub.GetLastConsumeTime(),
					oStub.GetLastErrMsg());
		}
	}
}
void TestDeleteACItems()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";
	std::string source = "";
	uint32_t sceneId = 0;
	uint64_t ACItemsSysNo = 0;
	std::string inReserve = "";
	std::string errmsg = "";
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数
	uint32_t dwResult = oStub.DeleteACItems(oCntlInfo, machineKey, source,
			sceneId, ACItemsSysNo, inReserve, errmsg, outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n", dwResult,
				oStub.GetLastConsumeTime());
	}
	else
	{
		printf("Error result[0x%x], time = %ld , errmsg = [%s]\n", dwResult,
				oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
void TestDeleteBankAccount()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(0);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "10.12.194.127";
	std::string source = "acaccountdao_test";
	uint32_t sceneId = 18;

	std::string inReserve = "";
	std::string errmsg = "";
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;

	for (int i = 10148; i <= 10149; i++)
	{
		uint64_t bankAccountSysNo = i;
		// TODO:替换函数参数
		uint32_t dwResult = oStub.DeleteBankAccount(oCntlInfo, machineKey,
				source, sceneId, bankAccountSysNo, inReserve, errmsg,
				outReserve);
		if (dwResult == 0)
		{
			std::cout << "Invoke OK!" << std::endl;
			printf("TestDeleteBankAccount OK result[0x%x], time = %ld\n",
					dwResult, oStub.GetLastConsumeTime());
		}
		else
		{
			printf(
					"TestDeleteBankAccount Error result[0x%x], time = %ld , errmsg = [%s]\n",
					dwResult, oStub.GetLastConsumeTime(),
					oStub.GetLastErrMsg());
		}
	}
}
void TestGetACItemsByFilter()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";
	std::string source = "";
	uint32_t sceneId = 0;
	erp::acaccount::po::CACItemsFilterPo bankAccountFilter;
	std::string inReserve = "";
	std::string errmsg = "";
	std::vector<erp::acaccount::po::CACItemsPo> aCItems;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数
	uint32_t dwResult = oStub.GetACItemsByFilter(oCntlInfo, machineKey, source,
			sceneId, bankAccountFilter, inReserve, errmsg, aCItems, outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n", dwResult,
				oStub.GetLastConsumeTime());
	}
	else
	{
		printf("Error result[0x%x], time = %ld , errmsg = [%s]\n", dwResult,
				oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
void TestGetACItemsBySysNos()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";
	std::string source = "";
	uint32_t sceneId = 0;
	std::set<uint64_t> sysNoList;
	std::string inReserve = "";
	std::string errmsg = "";
	std::map<uint64_t, erp::acaccount::po::CACItemsPo> aACItems;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数
	uint32_t dwResult = oStub.GetACItemsBySysNos(oCntlInfo, machineKey, source,
			sceneId, sysNoList, inReserve, errmsg, aACItems, outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n", dwResult,
				oStub.GetLastConsumeTime());
	}
	else
	{
		printf("Error result[0x%x], time = %ld , errmsg = [%s]\n", dwResult,
				oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
void TestGetBankAccountByFilter()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(0);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "10.12.194.127";
	std::string source = "acaccountdao_test";
	uint32_t sceneId = 18;
	erp::acaccount::po::CBankAccountFilterPo bankAccountFilter;
	std::string inReserve = "";
	std::string errmsg = "";
	std::vector<erp::acaccount::po::CBankAccountPo> bankAccount;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;

	//设置查询参数
	bankAccountFilter.SetBankAccountName("工商银行_20131029");
	bankAccountFilter.SetPage(1);
	bankAccountFilter.SetPageSize(5);

	// TODO:替换函数参数
	uint32_t dwResult = oStub.GetBankAccountByFilter(oCntlInfo, machineKey,
			source, sceneId, bankAccountFilter, inReserve, errmsg, bankAccount,
			outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("TestGetBankAccountByFilter OK result[0x%x], time = %ld\n",
				dwResult, oStub.GetLastConsumeTime());

		printf("徐威测试Filter搜索方法：\n");
		std::vector<erp::acaccount::po::CBankAccountPo>::const_iterator it =
				bankAccount.begin();
		for (; it != bankAccount.end(); it++)
		{
			printf("%s", it->ToString().c_str());
		}
	}
	else
	{
		printf(
				"TestGetBankAccountByFilter Error result[0x%x], time = %ld , errmsg = [%s]\n",
				dwResult, oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
void TestGetBankAccountBySysNos()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(0);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "10.12.194.127";
	std::string source = "acaccountdao_test";
	uint32_t sceneId = 18;
	std::set<uint64_t> sysNoList;
	std::string inReserve = "";
	std::string errmsg = "";
	std::map<uint64_t, erp::acaccount::po::CBankAccountPo> bankAccount;
	std::string outReserve = "";
	CACAccountAoStub4Web oStub;
	// TODO:替换函数参数

	sysNoList.insert(10000);
	sysNoList.insert(1);
	sysNoList.insert(10002);
	sysNoList.insert(10003);
	sysNoList.insert(10004);
	sysNoList.insert(10005);
	sysNoList.insert(10006);

	std::stringstream sysNos;
	for (std::set<uint64_t>::iterator it = sysNoList.begin();
			it != sysNoList.end(); it++)
	{
		sysNos << *it << ",";
	}
	printf("徐威测试，Ids：%s。\n", sysNos.str().c_str());

	uint32_t dwResult = oStub.GetBankAccountBySysNos(oCntlInfo, machineKey, source,
			sceneId, sysNoList, inReserve, errmsg, bankAccount, outReserve);
	if (dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("TestGetBankAccountByIds OK result[0x%x], time = %ld\n",
				dwResult, oStub.GetLastConsumeTime());

		printf("徐威测试，搜索数量：%zu条。\n", bankAccount.size());

		std::map<uint64_t, erp::acaccount::po::CBankAccountPo>::const_iterator it =
				bankAccount.begin();
		for (; it != bankAccount.end(); it++)
		{
			printf("%s", it->second.ToString().c_str());
		}
	}
	else
	{
		printf(
				"TestGetBankAccountByIds Error result[0x%x], time = %ld , errmsg = [%s]\n",
				dwResult, oStub.GetLastConsumeTime(), oStub.GetLastErrMsg());
	}
}
//测试主函数
int main(int argc, char** argv)
{
	//
	//测试主流程
	// 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
	// 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
	//
	Init();
	//TestAddAndUpdateACItems();
	TestAddAndUpdateBankAccount();
	//TestDeleteACItems();
	//TestDeleteBankAccount();
	//TestGetACItemsByFilter();
	//TestGetACItemsBySysNos();
	//TestGetBankAccountByFilter();
	TestGetBankAccountBySysNos();
	return 0;
}
